package ui.mainwidget;


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

import ui.MainWindow;
import ui.prefabricated.JumpAudioMouseAdapter;
import ui.resource.ResourceManager;
import ui.resource.ResourceURL;


public class Login extends org.eclipse.swt.widgets.Composite {
	private Button loginButton;

	{
		ResourceManager.registerResourceUser(this);
	}
	
	public Login(Composite parent, int style) {
		super(parent, style);
        this.addPaintListener(new PaintListener() {  
            public void paintControl(PaintEvent e) {  
                Point size  	=  Login.this.getSize();  
                Point location  =  Login.this.getLocation(); 
                Image image=ResourceManager.getImage(ResourceURL.getBackgroundImageURL());
                ImageData imageData=image.getImageData();
                e.gc.drawImage(image, 0, 0, imageData.width, imageData.height, location.x, location.y, size.x, size.y);  
            }
        });
		initGUI();
	}

	/**
	* Initializes the GUI.
	*/
	private void initGUI() {
		try {
			this.setSize(MainWindow.getStandardWidth(), MainWindow.getStandardHeight());
			this.setBackground(ResourceManager.getColor(192, 192, 192));
			FormLayout thisLayout = new FormLayout();
			this.setLayout(thisLayout);
			this.setOrientation(SWT.HORIZONTAL);
			{
				loginButton = new Button(this, SWT.PUSH | SWT.FLAT | SWT.UP | SWT.BORDER);
				FormData loginButtonLData = new FormData();
				loginButtonLData.left =  new FormAttachment(0, 1000, 277);
				loginButtonLData.top =  new FormAttachment(0, 1000, 378);
				loginButtonLData.width = 78;
				loginButtonLData.height = 28;
				loginButton.setLayoutData(loginButtonLData);
				loginButton.setText("login");
				loginButton.setOrientation(SWT.HORIZONTAL);
				loginButton.setDragDetect(false);
				loginButton.setImage(ResourceManager.getImage("img/sample.gif"));
				loginButton.addMouseListener(new LoginButtonAdapter());								
			}
			this.layout();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}

class LoginButtonAdapter extends JumpAudioMouseAdapter
{
	public void mouseDownStrategy(MouseEvent e) 
	{
		MainWindow.setMainWidget(new AppInfo(MainWindow.getShell(), SWT.DOUBLE_BUFFERED));
	}	
}

